package com.hulizuofang.wol.chat.server;

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManagerFactory;

import org.nicocube.appengine.util.dao.Dao;

import com.google.inject.Singleton;
import com.gwtplatform.dispatch.server.guice.HandlerModule;
import com.hulizuofang.wol.chat.client.action.SetLoginAction;
import com.hulizuofang.wol.chat.server.handler.CheckLoginActionHandler;

public class ServerModule extends HandlerModule {
	@Override
	protected void configureHandlers() {
		bind(ChatUserRepository.class);
		try {
			bind(Dao.class).toConstructor(Dao.class.getConstructor(PersistenceManagerFactory.class)).in(Singleton.class);
		} catch (SecurityException e) {
			throw new IllegalStateException("",e);
		} catch (NoSuchMethodException e) {
			throw new IllegalStateException("",e);
		}
		bind(PersistenceManagerFactory.class).toInstance(JDOHelper.getPersistenceManagerFactory("transactions-optional"));
		bindHandler(SetLoginAction.class, CheckLoginActionHandler.class);
	}
}
